/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.io.FileInputStream;
import java.io.ObjectInputStream;

/**
 * <p>Project: jse2303 - ObjectInputStreamDemo
 * <p>Powered by webrx On 2023-07-24 14:18:07
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class ObjectInputStreamDemo {
    public static void main(String[] args) {
        //Student st = new Student(100, "李四", 50);
        //System.out.println(st);

        //将st对象保存到文件中 ObjectOutputStream 流用于保存实现import java.io.Serializable接口对象
        //try (var os = new ObjectOutputStream(new FileOutputStream("st.dat"))) {
        //    os.writeObject(st);
        //} catch (Exception e) {
        //    e.printStackTrace();
        //}

        //从文件中读取java 对象
        try (var is = new ObjectInputStream(new FileInputStream("st.dat"))) {
            Student s = (Student) is.readObject();
            System.out.println(s);
            System.out.println(s.getId());
            System.out.println(s.getName());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

